package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurBindOpen;
import com.js.purs.service.IPurBindOpenService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 候选人公示Controller
 * 
 * @author lzq
 * @date 20240715
 */
@RestController
@RequestMapping("/open")
public class PurBindOpenController extends BaseController
{
    @Autowired
    private IPurBindOpenService purBindOpenService;

    /**
     * 查询候选人公示列表
     */

    @GetMapping("/list")
    public TableDataInfo list(PurBindOpen purBindOpen)
    {
        startPage();
        List<PurBindOpen> list = purBindOpenService.selectPurBindOpenList(purBindOpen);
        return getDataTable(list);
    }

    /**
     * 导出候选人公示列表
     */
    @RequiresPermissions("purs:open:export")
    @Log(title = "候选人公示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurBindOpen purBindOpen)
    {
        List<PurBindOpen> list = purBindOpenService.selectPurBindOpenList(purBindOpen);
        ExcelUtil<PurBindOpen> util = new ExcelUtil<PurBindOpen>(PurBindOpen.class);
        util.exportExcel(response, list, "候选人公示数据");
    }

    /**
     * 获取候选人公示详细信息
     */

    @GetMapping(value = "/{bindCode}")
    public AjaxResult getInfo(@PathVariable("bindCode") String bindCode)
    {
        return success(purBindOpenService.selectPurBindOpenByBindCode(bindCode));
    }

    /**
     * 新增候选人公示
     */
    @RequiresPermissions("purs:open:add")
    @Log(title = "候选人公示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurBindOpen purBindOpen)
    {
        System.out.println("purBindCode:"+purBindOpen.toString());
        return toAjax(purBindOpenService.insertPurBindOpen(purBindOpen));
    }

    /**
     * 修改候选人公示
     */
    @RequiresPermissions("purs:open:edit")
    @Log(title = "候选人公示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurBindOpen purBindOpen)
    {
        return toAjax(purBindOpenService.updatePurBindOpen(purBindOpen));
    }

    /**
     * 删除候选人公示
     */
    @RequiresPermissions("purs:open:remove")
    @Log(title = "候选人公示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{openIds}")
    public AjaxResult remove(@PathVariable Long[] openIds)
    {
        return toAjax(purBindOpenService.deletePurBindOpenByOpenIds(openIds));
    }


}
